package com.simple.common.framework;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.filter.AssignableTypeFilter;

/**
 * 扫描
 * @author yasud
 * @date 2020年09月16日 18:25
 * @description
 */
public class Scan implements ImportBeanDefinitionRegistrar {

    public static boolean enableRetrofit;


    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(
                metadata.getAnnotationAttributes(Init.class.getName(), true));

        enableRetrofit = attributes.getBoolean("enableRetrofit");
        ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(registry);
        classPathBeanDefinitionScanner.addIncludeFilter(new AssignableTypeFilter(Scan.class));
        classPathBeanDefinitionScanner.scan("com.simple.common.framework");
    }
}
